'use strict';
const path = require('path');
const webpack = require('webpack');
const ExtractTextPlugin = require("extract-text-webpack-plugin");


module.exports = {
  entry: {
    'plugins': [
      'vue',
      'axios',

      './src/public/libs/zepto.js',
      './src/public/libs/filter.js',

      'normalize.css',
      './src/public/style/base.css'
    ]
  },
  resolve: {
    modules: [path.resolve(__dirname, "src"), 'node_modules/'],
    extensions: [".js", '.vue', ".json"],
    alias: {
      'vue$': 'vue/dist/vue.esm.js',
      '@': path.resolve(__dirname, 'src'),
      'components': path.resolve(__dirname, 'src/components'),
      'public': path.resolve(__dirname, 'src/public')
    }
  },
  output: {
    path: path.join(__dirname, './dist/common'),
    filename: '[name].dll.js',
    library: '[name]_library'
  },

  module: {
    rules: [
      {
        enforce: 'pre',
        test: /.vue$/,
        loader: 'eslint-loader',
        exclude: /node_modules/
      },
      {
        test: /iview.src.*?js$/,
        loader: 'babel-loader'
      },
      {
        test: /\.js$/,
        loader: 'babel-loader',
        exclude: /node_modules/
      },
      {
        test: /\.vue$/,
        loader: 'vue-loader',
        options: {
          minimize: true,
          postcss: [
            require('postcss-salad'),
            require('postcss-px2rem')({ remUnit: 75 }),
            require('postcss-cssnext')()
          ],
          loaders: {
            css: ExtractTextPlugin.extract({
              use: 'css-loader!less-loader',
              fallback: 'vue-style-loader' // <- 这是vue-loader的依赖，所以如果使用npm3，则不需要显式安装
            })
          }
        }
      },
      {
        test: /\.css$/,
        use: [
          'style-loader',
          'css-loader',
          {
            loader: 'postcss-loader',
            options: {
              minimize: true,
              plugins: [
                require('postcss-salad'),
                require('postcss-px2rem')({ remUnit: 75 }),
                require('postcss-cssnext')()
              ]
            }
          }
        ]
      },
      {
        test: /\.(png|jpg|jpeg|gif|eot|ttf|woff|woff2|svg|svgz)(\?.+)?$/,
        use: [
          {
            loader: 'url-loader',
            options: {
              limit: 8192,
              // name: "[path][hash][name].[ext]"
              name: "imgs/[sha512:hash:base64:7].[ext]?[hash]"
            }
          }
        ]
      }
    ]
  },

  plugins: [
    new webpack.DefinePlugin({
      "process.env": {
        NODE_ENV: JSON.stringify("production")
      }
    }),
    new webpack.DllPlugin({
      path: "./manifest.json",
      name: '[name]_library',
      context: __dirname
    })
  ]
};
